package com.jixu.numberapp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jixu.numberapp.entity.Game;
import com.jixu.numberapp.entity.Number;
import com.jixu.numberapp.mapper.NumberMapper;
import com.jixu.numberapp.service.NumberService;
import com.jixu.numberapp.utils.GameRule;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * Title:
 * Description:
 * Create Time: 2023/2/22 14:36
 *
 * @version 1.0
 * @author: aaa
 */
@Service
public class NumberServiceImpl extends ServiceImpl<NumberMapper, Number> implements NumberService {
    @Override
    @Async("asyncServiceExecutor")
    public Game beginGame(Game game, ThreadPoolTaskExecutor executor) {
        System.out.println(Thread.currentThread().getName() + "处理任务ing...");
        try {
            GameRule.guessNumber(this, game.getMemberName(), executor);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return game;
    }
}
